home *** CD-ROM | disk | FTP | other *** search
- /*
- CDStop - An XFCN to stop at absolute minute, second, block
- ©Apple Computer, Inc. 1988
- All Rights Reserved.
-
- 88/10/08 BL°B First Version
-
- To compile and link this file using Macintosh Programmer's Workshop,
-
- C -q2 CDStop.c
- link -sn Main=CDStop -sn STDIO=CDStop ∂
- -sn INTENV=CDStop -rt XFCN=42 ∂
- -m CDSTOP CDStop.c.o "{CLibraries}"CRuntime.o ∂
- "{CLibraries}"StdCLib.o ∂
- -o HyperCommands
-
- This link directive puts the XCMD in the file "HyperCommands".
- Substitute the name of the stack you want it in. To move XCMDs
- between stacks, use ResEdit. They can be in an individual stack,
- the Home stack, the HyperCard application, or the System File.
-
- */
-
- #include <cd.h>
-
- /* prototype definitions for functions */
- /* prototype definitions for functions */
- void ExtractBCD(char *, long *);
- OSErr AStop(XCmdBlockPtr, short, long, long, long);
- OSErr ASearch(XCmdBlockPtr, short, short, long, long, long);
-
- /* **** WARNING: DO NOT USE GLOBAL VARIABLES! **** */
-
-
- /************************************************************************
- *
- * Function: CDStop
- *
- * Purpose: Stop absolute minute, second and block
- *
- * Returns: result of driver call to Stop
- * normally 0, but could have parameter error or
- * other error if non-existent block is specified
- *
- * Side Effects:
- *
- * Description: We need three parameters or no parameters:
- * 1) the minute
- * 2) the second
- * 3) the block
- * Get the famous global ioRefNum (set by CDOpen())
- * Extract the minute, second and block and set a
- * stop at that point. If we aren't passed any
- * parameters, set the stop at the end of the disc and
- * search to the beginning of the disc.
- *
- ************************************************************************/
- pascal void
- CDStop(paramPtr)
- XCmdBlockPtr paramPtr;
- {
- Str31 returnString;
- OSErr result;
- long minute;
- long second;
- long block;
- short ioRefNum;
- Handle refHandle;
-
- /* Must be no parameters, or three parameters */
- if ((paramPtr->paramCount) != 0)
- {
- if ((paramPtr->paramCount) != 3)
- {
- /* Report error in parameters by returning -1 */
- NumToStr(paramPtr, (long) -1, &returnString);
- paramPtr->returnValue = PasToZero(paramPtr, (StringPtr) &returnString);
- return;
- }
- }
-
- /* Get the global ioRefNum and convert it. */
- refHandle = GetGlobal(paramPtr, GLOBALNAME);
- ioRefNum = atoi(*(refHandle));
- DisposHandle(refHandle);
- ioRefNum &= 0xFFFF; /* remove vRefNum; not needed. */
-
- result = noErr;
-
- if ((paramPtr->paramCount) == 0)
- {
- result = DiscTime(ioRefNum, &minute, &second, &block);
- if (result == noErr)
- {
- TimeDiff(&minute, &second, &block, minute, second, block, 0L, 0L, 1L);
- result = AStop(paramPtr, ioRefNum, minute, second, block);
- }
- if (result == noErr) /* search to 1st track */
- result = TrackStart(ioRefNum, 1, &minute, &second, &block);
- if (result == noErr)
- result = ASearch(paramPtr, ioRefNum, 0, minute, second, block);
-
- }
- else
- {
- /* First param is minute. Convert it to a BCD number */
- ExtractBCD((char *)*(paramPtr->params[0]), &minute);
-
- /* Second param is second. Convert it to a BCD number */
- ExtractBCD((char *)*(paramPtr->params[1]), &second);
-
- /* Third param is block. Convert it to a BCD number */
- ExtractBCD((char *)*(paramPtr->params[2]), &block);
-
- minute = BCD2DECIMAL(minute);
- second = BCD2DECIMAL(second);
- block = BCD2DECIMAL(block);
- result = AStop(paramPtr, ioRefNum, minute, second, block);
- }
-
-
- /* Convert result to string & return it */
- NumToStr(paramPtr, (long) result, &returnString);
- paramPtr->returnValue = PasToZero(paramPtr, (StringPtr) &returnString);
- }
-
- /************************************************************************
- *
- * Function: ExtractBCD
- *
- * Purpose: Extract number in BCD from PString
- *
- * Returns: nothing
- *
- * Side Effects: *track gets a new value
- *
- * Description: Extract number in BCD from Cstring "name".
- * "name" is always of the form "XX", where XX
- * ranges from "1" to "99"
- *
- ************************************************************************/
- void
- ExtractBCD(name, number)
- char *name;
- long *number;
- {
- long t;
-
- t = 0;
- while (*name != 0)
- {
- t *= 16;
- t += *name - '0';
- name++;
- }
-
- *number = t;
- }
-
- /************************************************************************
- *
- * Function: AStop
- *
- * Purpose: stop playing at an absolute minute, second, block
- *
- * Returns: OSErr. Probably either
- * noErr everything's hunky-dory!
- * paramErr you messed up the call somehow.
- *
- * Side Effects: stops play.
- *
- * Description: pass in the absolute minute, second and block in BCD.
- *
- ************************************************************************/
- OSErr
- AStop(paramPtr, refNum, minute, second, block)
- XCmdBlockPtr paramPtr;
- short refNum;
- long minute;
- long second;
- long block;
- {
- CDPlayParam myPB;
- short playMode;
- Handle refHandle;
- OSErr result;
-
- /* Get the global ioRefNum and convert it. */
- refHandle = GetGlobal(paramPtr, PLAYMODE);
- playMode = atoi(*(refHandle));
- DisposHandle(refHandle);
-
- myPB.ioCompletion = 0;
- myPB.ioNamePtr = (char *) 0;
- myPB.ioVRefNum = 1;
- myPB.ioCRefNum = refNum;
- myPB.csCode = ASTOP;
-
- myPB.addrFormat = AMSFADDR;
- myPB.unused = 0;
- myPB.minute = (char) DECIMAL2BCD(minute); /* must be in BCD */
- myPB.second = (char) DECIMAL2BCD(second); /* must be in BCD */
- myPB.block = (char) DECIMAL2BCD(block); /* must be in BCD */
- myPB.stopAddress = 0;
- myPB.playMode = playMode;
- result = PBControl(&myPB, false);
- return result;
- }
-
-
-
- /************************************************************************
- *
- * Function: ASearch
- *
- * Purpose: start Searching at an absolute minute, second, block
- *
- * Returns: OSErr. Probably either
- * noErr everything's hunky-dory!
- * paramErr you messed up the call somehow.
- *
- * Side Effects: positions CD at the specified location and pauses or
- * plays, depending upon flag. 0 = pause, 1 = play.
- *
- * Description: pass in the absolute minute, second and block in BCD.
- *
- ************************************************************************/
- OSErr
- ASearch(paramPtr, refNum, flag, minute, second, block)
- XCmdBlockPtr paramPtr;
- short refNum;
- short flag; /* 0 = pause, 1 = play. */
- long minute;
- long second;
- long block;
- {
- CDParam myPB;
- short playMode;
- Handle refHandle;
-
- /* Get the global ioRefNum and convert it. */
- refHandle = GetGlobal(paramPtr, PLAYMODE);
- playMode = atoi(*(refHandle));
- DisposHandle(refHandle);
-
- myPB.ioCompletion = 0;
- myPB.ioNamePtr = (char *) 0;
- myPB.ioVRefNum = 1;
- myPB.ioCRefNum = refNum;
- myPB.csCode = ASEARCH;
-
- myPB.csParam[0] = 0;
- myPB.csParam[1] = AMSFADDR;
- myPB.csParam[2] = 0; /* must be in BCD */
- myPB.csParam[3] = (char) DECIMAL2BCD(minute); /* must be in BCD */
- myPB.csParam[4] = (char) DECIMAL2BCD(second); /* must be in BCD */
- myPB.csParam[5] = (char) DECIMAL2BCD(block); /* must be in BCD */
- myPB.csParam[6] = 0;
- myPB.csParam[7] = flag;
- myPB.csParam[8] = 0;
- myPB.csParam[9] = playMode;
- return (PBControl(&myPB, false));
- }
-
-
- /* C routines for HyperCard callbacks */
- #include <XCmdGlue.inc.c>
-